/**
 * @date   2011-5-2
 * @author tianye
 */
package cn.edu.dlut.WingGame.Tools;

import java.util.ArrayList;
import java.util.Hashtable;

import cn.edu.dlut.WingGame.Object.WingObject;

public class ObjectContainer {

	public Hashtable<Integer, WingObject> mObjectList;
	public ArrayList<Integer> mTable;

	public ObjectContainer() {
		mObjectList = new Hashtable<Integer, WingObject>();
		mTable = new ArrayList<Integer>();
	}

	public boolean addObject(WingObject obj) {
		mObjectList.put(obj.getID(), obj);
		mTable.add(obj.getID());
		return true;
	}

	public synchronized boolean delObject(int index) {
		mObjectList.remove(mTable.get(index));
		mTable.remove(index);
		return true;
	}

	public synchronized boolean delObjectByID(int id) {
		mObjectList.remove(id);
		mTable.remove(new Integer(id));
		return true;
	}

	public synchronized boolean delAllObject() {
		try {
			mObjectList.clear();
			mTable.clear();
			return true;
		} catch (Exception e) {
			return false;
		}

	}

	public WingObject getObject(int index) {
		return mObjectList.get(mTable.get(index));
	}

	public WingObject getObjectByID(int id) {
		return mObjectList.get(id);
	}

	public int getSize() {
		return mTable.size();
	}

	public boolean isEmpty() {
		return mTable.isEmpty();
	}

}
